import store from "@/store";
import axios from "axios";
const instance = axios.create({
  baseURL: "http://192.168.113.249:8081/cms",
  timeout: 5000,
});
// 请求之前
instance.interceptors.request.use(
  (config) => {
    // console.log("每一次发起请求前，都会先执行这里的代码");
    // console.log(config); //config本次请求的配置信息
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

// 获得数据之前
instance.interceptors.response.use(
  (res) => {
    let response = res.data;
    if (res.data.code != 0) {
      store.dispatch("showToast/asyncChangeStatus", {
        content: response.message,
        type: "danger",
      });
      return false;
    }
    return res.data;
  },
  (err) => {
    return Promise.reject(err);
  }
);
export default instance;
